package com.javasm.mb_store_api_final.giftsandgoods.gift.controller;

import com.javasm.common.Parameter;
import com.javasm.common.R;
import com.javasm.mb_store_api_final.giftsandgoods.gift.entity.GmGift;
import com.javasm.mb_store_api_final.giftsandgoods.gift.entity.GmGift2Goods;
import com.javasm.mb_store_api_final.giftsandgoods.gift.entity.GmGoods2Gifts;
import com.javasm.mb_store_api_final.giftsandgoods.gift.service.GmGift2GoodsService;
import com.javasm.mb_store_api_final.giftsandgoods.gift.service.GmGiftService;
import com.javasm.mb_store_api_final.giftsandgoods.gift.vo.Gifts2GoodsVo;
import com.javasm.mb_store_api_final.giftsandgoods.goods.entity.GgGoods;
import org.apache.poi.ss.formula.functions.Now;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className:Gift2GoodsController
 * @author: zhl
 * @date:2024/8/111:24
 * @since : jdk11
 */
@RestController
@RequestMapping("/gift2goods")
public class Gift2GoodsController {
    @Resource
    GmGiftService gmGiftService;
    @Resource
    GmGift2GoodsService gmGift2GoodsService;
    @RequestMapping("/getGiftNum/{id}")
    public R getGift(@PathVariable Integer id){
        GmGift gift = gmGiftService.getById(id);
        if(gift!=null){
            return R.ok(gift);
        }
        return null;
    }
    @PostMapping("/getGifts2GooodsVo")
    public R getGifts2GooodsVo(@RequestBody Gifts2GoodsVo g2gVo){
        List<Gifts2GoodsVo> gifts2GoodsVo=gmGift2GoodsService.listGifts2GoodsVo(g2gVo);
        return R.ok(gifts2GoodsVo);
    }
    @GetMapping("/getTatol")
    public R getTatol(){
        long count = gmGift2GoodsService.getTatol();
        return R.ok(count);
    }
    @GetMapping("/paramList")
    public R paramList(){
        List<String> params=gmGift2GoodsService.listgtype();
        return R.ok(params);
    }
    @GetMapping("/getGifts2GoodsBYId/{id}")
    public R getGiftId(@PathVariable Integer id){
        GmGift2Goods gift2Goods = gmGift2GoodsService.selectById(id);
        return R.ok(gift2Goods);
    }
    @GetMapping("/getGift2GoodsDetail/{id}")
    public R getGift2GoodsDetail(@PathVariable Integer id){
        GgGoods ggGoods = gmGift2GoodsService.getDetailById(id);
        return R.ok(ggGoods);
    }
    @PostMapping("/updateGifts2Goods")
    public R updateGifts2Goods(@RequestBody GmGift2Goods gift2Goods){
        boolean b = gmGift2GoodsService.updateById1(gift2Goods);
        return R.ok(b);
    }
    //审核通过 减库存
    @GetMapping("/updateGiftNum/{id}/{count}")
    public R updateGiftNum(@PathVariable Integer id,@PathVariable Integer count){
        Parameter.check(id,count);
        boolean b = gmGift2GoodsService.updateGiftNum(id, count);
        if(b){
            return R.ok(b);
        }
        return null;
    }
    @DeleteMapping("/deleteGift2Goods/{id}")
    public R deleteGifts2Goods(@PathVariable Integer id){
        boolean b = gmGift2GoodsService.delById(id);
        if(b){
            return R.ok(b);
        }
        return null;
    }
    @PostMapping("/addGift2Goods")
    public R addGift2Goods(@RequestBody GmGift2Goods g2g){

        boolean b = gmGift2GoodsService.saveGift2Goods(g2g);
        if(b){
            return R.ok(b);
        }
        return null;
    }


}
